package hot_100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 划分字母区间 {
    public static void main(String[] args) {
        List<Integer> eccbbbbdec = partitionLabels("vhaagbqkaq");
        System.out.println(eccbbbbdec);
    }

    public static List<Integer> partitionLabels(String s) {
        char[] chars = s.toCharArray();
        int n = s.length();
        int[] ss = new int[26];
        for (int i = 0; i < n; i++) {
            int f = chars[i] - 'a';
            ss[f] = i;
        }
        ArrayList<Integer> ans = new ArrayList<>();
        int j = 0;
        int end = 0;
        for (int i = 0; i < n; i++) {
            int f = chars[i] - 'a';
            end = Math.max(end, ss[f]);
            if (i == end) {
                ans.add(end - j + 1);
                j = i + 1;
            }
        }
        return ans;
    }
}
